# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lowjs
pkgver=1.6.2
# Keep in sync with submodules in deps/.
_gitrev_open62541="8828fa712d7076962aa67d2a0542d7892c34d964"
_commit_sha="d14bd8de2d"
_commit_date="2021-02-28T00:53:17Z"
pkgrel=2
pkgdesc="A port of Node.JS with far lower system requirements"
url="https://www.neonious.com/lowjs/"
arch="all !s390x !ppc64le !riscv64"  # excluded archs are not supported
license="custom"
makedepends="
	c-ares-dev
	cmake
	duktape-dev
	jq
	mbedtls2-dev
	npm
	python3
	"
subpackages="$pkgname-doc"
source="https://github.com/neonious/lowjs/archive/v$pkgver/$pkgname-$pkgver.tar.gz
	https://github.com/neonious/open62541/archive/$_gitrev_open62541/open62541-$_gitrev_open62541.tar.gz
	use-npm-ci.patch
	open62541-gcc9.patch
	unbundle-c-ares.patch
	unbundle-mbedtls.patch
	make-flags.patch
	musl.patch
	unbundle-duktape.patch
	test.js
	"
builddir="$srcdir/$pkgname-$pkgver"
options="net" # npm

prepare() {
	rm -Rf deps/open62541
	mv ../open62541-$_gitrev_open62541 deps/open62541

	default_prepare
}

build() {
	unset LDFLAGS  # fails to build with -Wl,--as-needed

	make -j1 \
		LOW_LIB_PATH="../lib/low/" \
		LOW_VERSION="${_commit_date}_${_commit_sha}"
}

check() {
	# XXX: See https://github.com/neonious/lowjs/issues/81
	#( cd test/tests_script && npm ci )
	#npm run test -- run

	test -L lib/low || ln -s . lib/low
	./bin/low "$srcdir"/test.js
	rm lib/low
}

package() {
	install -d "$pkgdir"/usr/lib/low
	cp -r lib/* "$pkgdir"/usr/lib/low/
	rm "$pkgdir"/usr/lib/low/BUILT

	install -D -m 0755 bin/low "$pkgdir"/usr/bin/low
	install -D -m 0644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

sha512sums="
d013b1d631d1056baf1e5b12f606b1d14ebd3355a9cc75e5e1b6179e65918c5a5d68b79058c6ea56c848729eee74c39386451fd17c6de53667a3b542b1256c83  lowjs-1.6.2.tar.gz
8d992a3a8fdf1717af2497c0d2d5e9e27e490b29253da78ecd64a6ff866fcef4f7114cb7cb073a8a862efff16eddfcb9416a9c64a2659b3bc9c2294e4cec3734  open62541-8828fa712d7076962aa67d2a0542d7892c34d964.tar.gz
b8aecec6aa87eb2ab7ffecaca1989f922042ee534612229872bad10bc0e304951cb66a1d1aa3ba4e76384ca2ea28b8c5b7176eacf6b7df3d59ea7435b7894a48  use-npm-ci.patch
c2c7f10d327d2e56d2824db02c647c05773c652179f40eff7b376dfbf7eecd72b7d07c18458d59fd195993b261cb9a48e9f521ccb1a519807270c036ed8d5746  open62541-gcc9.patch
37d8810d8e89354ed8d908395ba21b7795049ff990f2d6d795d2458f511c4a9352c734f989c9eb2a54f8a06475769abe4051056d4c92e613d12103168790d361  unbundle-c-ares.patch
bc0d847cabf195911b127768ac99d7876a2c43b0bb7ed359c9691f525560b302c3ee404fb16a0245acf9d04b912dabb89dd6f9584bafeeb6fe3b07eeaaac7cdb  unbundle-mbedtls.patch
6a7771e749bf567819bb028738cf38da71ab7a397211de410e2406dc3a2e87bc8d4e4c4804e25f0a76b2dc96836b020ac91d8a32c806eb2874fe65deee2c51f9  make-flags.patch
e42dfb980acacdd4bd042bad0e625562122b84037fa8b25c2bbe8dee2b6598505205d5aa9ecc66cee5ae2d830bd847e74147323c9db183789dc09f3be58fc71c  musl.patch
03b1a8fb5ef165c0b64165e191ad4f15bfbfadde58cc46b149943bfefaeebe2d0819cf54ed28c7935640545b523fcaa73abf0d8efa9988bca70d5791988e84d5  unbundle-duktape.patch
9ee7d585c9ce17ca00e86e0f74976883fa14e70f3728cf230256f2570dafdaa3adeae1922de5f0dcb74bba8577f9394c54441bc3729c1bb58bb6a298c26651d0  test.js
"
